<template>
	<view class="root">
		<view class="cen">
			<br>
			<span style="color:#FFFF">登陆</span>
			<br>
			<input v-model="name" class="color" type="text" value="" placeholder="账号" />
			<br>
			<input v-model="password" class="color" type="text" value="" placeholder="密码" password="" />
			<br>
			
			<view class="row">
				<button @click="login" type="default">登陆</button>
				<button @click="regi" type="default">注册</button>
			</view>
			

		</view>
		


	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'',
				password:''

			}
		},
		methods: {
			login(){
				if(this.name!=''&& this.password!=''){
					uni.request({
						url:'http://192.168.1.3:9090/user/login',
						method:'POST',
						data:{
							name:this.name,
							password:this.password
						}
					}).then(res=>{
						if(res.data.state=='ok'){
							
							uni.showToast({
								title:"登陆成功"
							})
							uni.setStorage({
								key:"name",
								data:res.data.name
							})
							// uni.redirectTo({
							// 	url:'/pages/index/index'
							// })
							uni.switchTab({
								url:'/pages/index/index'
							})
						}else{
							uni.showToast({
								icon:'error',
								title:'登陆失败，请检查账号或密码'
							})
						}
					})
				}else{
					uni.showToast({
						icon:'error',
						title:'登陆失败，请检查账号或密码'
					})
				}
				
			},
			regi(){
				
			uni.redirectTo({
				url:'/pages/register/register'
			})
				
				
			}

		}
	}
</script>

<style>
	.root {
		width: 100%;
		height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.cen {
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: gray;
		border-radius: 20rpx;
		width: 60%;
		height: 500rpx;
	}
	.color{
		background-color: #FFFF;
	}
	.row{
		display: flex;
		flex-direction: row;
		
	}
</style>